import time

import page
from base.base import Base


class PageBackUserList(Base):
    # 点击用户链接
    def page_click_user_link(self):
        self.base_click_element(page.back_user_manage)

    # 点击用户列表链接
    def page_click_user_list_link(self):
        self.base_click_element(page.back_user_list)

    # 切换到用户列表iframe
    def page_switch_user_list_iframe(self):
        self.base_switch_to_iframe(page.back_user_list_iframe)

    # 点击添加按钮
    def page_click_add_btn(self):
        self.base_click_element(page.back_add_btn)

    # 输入用户名
    def page_input_username(self, username):
        self.base_in_element_input(page.back_input_username, username)

    # 输入昵称
    def page_input_nickname(self, nickname):
        self.base_in_element_input(page.back_input_nickname, nickname)

    # 输入手机号码
    def page_input_phone(self, phone):
        self.base_in_element_input(page.back_input_phone, phone)

    # 输入电子邮箱
    def page_input_email(self, email):
        self.base_in_element_input(page.back_input_email, email)

    # 输入所在省
    def page_input_province(self, province):
        self.base_in_element_input(page.back_input_province, province)

    # 输入所在市
    def page_input_city(self, city):
        self.base_in_element_input(page.back_input_city, city)

    # 输入所在区
    def page_input_district(self, district):
        self.base_in_element_input(page.back_input_district, district)

    # 输入详细地址
    def page_input_address(self, address):
        self.base_in_element_input(page.back_input_address, address)

    # 输入有效积分
    def page_input_valid_points(self, points):
        self.base_in_element_input(page.back_input_valid_points, points)

    # 输入锁定积分
    def page_input_locked_points(self, points):
        self.base_in_element_input(page.back_input_locked_points, points)

    # 输入生日
    def page_input_birthday(self, birthday):
        self.base_in_element_input(page.back_input_birthday, birthday)

    # 输入邀请人ID
    def page_input_inviter_id(self, inviter_id):
        self.base_in_element_input(page.back_input_inviter_id, inviter_id)

    # 输入登录密码
    def page_input_password(self, password):
        self.base_in_element_input(page.back_input_password, password)

    def page_scroll_to_status(self):
        self.base_scroll_to_element(page.back_select_user_status)

    # 选择性别
    def page_select_gender(self):
        self.base_click_element(page.back_select_gender)

    # 选择用户状态
    def page_select_user_status(self):
        self.base_click_element(page.back_select_user_status)

    # 提交添加按钮
    def page_click_submit_add(self):
        self.base_click_element(page.back_btn_submit_add)

    # 点击编辑按钮
    def page_click_update_btn(self):
        self.base_click_element(page.get_user_id()['back_update_user'])

    # 点击删除按钮
    def page_click_delete_btn(self):
        self.base_click_element(page.get_user_id()['back_delete_user'])
        self.base_click_element(page.product_confirm_btn)
        time.sleep(1)

    # 清空输入框
    def page_clear_input(self):
        self.base_clear_input(page.back_input_nickname)

    # 获得截屏
    def page_get_screenshot(self):
        self.base_get_img()

    # 切换到用户列表页面
    def page_switch_to_user_list(self):
        self.page_click_user_link()
        time.sleep(1)
        self.page_click_user_list_link()
        time.sleep(1)
        self.page_switch_user_list_iframe()
        time.sleep(1)
        self.page_click_add_btn()
        time.sleep(1)

    # 输入用户信息
    def page_input_user_info(self, username, password, nickname=None, phone=None, email=None,
                             province=None, city=None, district=None, address=None,
                             valid_points=0, locked_points=0, birthday=None, inviter_id=None):
        self.page_input_username(username)
        self.page_input_password(password)
        if nickname:
            self.page_input_nickname(nickname)
        if phone:
            self.page_input_phone(phone)
        if email:
            self.page_input_email(email)
        if province:
            self.page_input_province(province)
        if city:
            self.page_input_city(city)
        if district:
            self.page_input_district(district)
        if address:
            self.page_input_address(address)
        self.page_input_valid_points(valid_points)
        self.page_input_locked_points(locked_points)
        if birthday:
            self.page_input_birthday(birthday)
        if inviter_id:
            self.page_input_inviter_id(inviter_id)
        self.page_scroll_to_status()
        self.page_select_gender()
        self.page_select_user_status()
        self.page_click_submit_add()
        time.sleep(1)

    # 编辑用户信息
    def page_update_user_nickname(self, nickname):
        self.page_click_update_btn()
        self.page_clear_input()
        self.page_input_nickname(nickname)
        self.page_click_submit_add()
        time.sleep(1)
